#include <iostream>
#include <string>

// 定义状态枚举
enum State {
    IDLE,
    RUNNING,
    STOPPED
};

// 状态机类
class StateMachine {
private:
    State currentState;

public:
    // 构造函数，初始化状态为 IDIE
    StateMachine() : currentState(IDLE) {}

    // 获取当前状态
    State getCurrentState() const {
        return currentState;
    }

    // 处理事件并更新状态
    void handleEvent(const std::string& event) {
        if (currentState == IDLE && event == "start") {
            std::cout << "从 0 转换到 1" << std::endl;
            currentState = RUNNING;
        } else if (currentState == RUNNING && event == "stop") {
            std::cout << "从 1 转换到 2" << std::endl;
            currentState = STOPPED;
        } else if (currentState == STOPPED && event == "reset") {
            std::cout << "从 2 转换到 0" << std::endl;
            currentState = IDLE;
        } else {
            std::cout << "在状态 " << currentState << " 下没有为事件 " << event << " 定义转换" << std::endl;
        }
    }
};

int main() {
    StateMachine stateMachine;

    // 模拟事件处理
    stateMachine.handleEvent("start");
    stateMachine.handleEvent("continue"); // 无效事件，不会触发状态转换
    stateMachine.handleEvent("stop");
    stateMachine.handleEvent("reset");
    stateMachine.handleEvent("stop"); // 无效事件，因为当前状态是 IDLE

    // 输出最终状态
    std::string finalState;
    switch (stateMachine.getCurrentState()) {
        case IDLE:
            finalState = "0";
            break;
        case RUNNING:
            finalState = "1";
            break;
        case STOPPED:
            finalState = "2";
            break;
    }
    std::cout << "最终状态: " << finalState << std::endl;

    return 0;
}